<%@ page import="com.example.oa.Employee" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户管理页面</title>
  <script>
    function del(){
      return confirm("是否要删除此员工？");
    }
  </script>
</head>
<body>
<%
//  request.setCharacterEncoding("UTF-8");
//  response.setCharacterEncoding("UTF-8");
//  if(session.getAttribute("name") == null || session.getAttribute("roleId").equals(0)){
//    request.setAttribute("message","您没有访问权限，请重新登陆！");
//    request.getRequestDispatcher("index.jsp").forward(request,response);
//    return;
//  }
  ArrayList<Employee> employees = (ArrayList<Employee>) session.getAttribute("employeeList");
%>
<h1>管理员页面</h1>
欢迎您：<%=session.getAttribute("name")%>
<h2>员工列表</h2>
<a href="http://localhost:8080/OA/admin/add.jsp">添加员工</a>
<table border="1" cellpadding="0" cellspacing="0">
  <tr>
    <th>ID</th>
    <th>姓名</th>
    <th>年龄</th>
    <th>性别</th>
    <th>操作</th>
  </tr>
  <%
    if(employees == null){
      request.setAttribute("message", "Invalid visit.");
      request.getRequestDispatcher("/OA/index.jsp").forward(request, response);
    }
    for (Employee employee : employees) {
      out.print("<tr>");
  %>

  <td><%=employee.getId()%></td>
  <td><%=employee.getName()%></td>
  <td><%=employee.getAge()%></td>
  <td><%=employee.getGender().equals("M")?"男":"女"%></td>
  <td><a href="/OA?action=deleteById&id=<%=employee.getId()%>" onclick="return del()">删除</a>
    <a href="/OA?action=findById&id=<%=employee.getId()%>">修改</a>
    <a href="/OA?action=detail&id=<%=employee.getId()%>">detail</a>
  </td>

  <%
      out.print("</tr>");
    }
  %>
  <hr>
  <c:forEach var="employee" items="${sessionScope.employeeList}">
    <tr>
      <td>${employee.id}</td>
      <td>${employee.name}</td>
      <td>${employee.age}</td>
      <td>${employee.gender}</td>
      <td><a href="/OA?action=findById&id=${employee.id}">EDIT</a>
      <a href="/OA?action=deleteById&id=${employee.id} " onclick="return del()">REMOVE</a>
      <a href="/OA?action=detail&id=${employee.id}">DETAIL</a>
      </td>
    </tr>
  </c:forEach>



</table>
<a href="${pageContext.request.contextPath}/OA?action=sign_out">退出登陆</a>

</body>
</html>
